package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TOrderItem;
import com.mall.business.service.ITOrderItemService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 订单明细项Controller
 *
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/business/orderitem" )
public class TOrderItemController extends BaseController {
    @Autowired
    private ITOrderItemService tOrderItemService;

/**
 * 查询订单明细项列表
 */
//@RequiresPermissions("business:orderitem:list")
@GetMapping("/list" )
    public TableDataInfo list(TOrderItem tOrderItem) {
        startPage();
        List<TOrderItem> list = tOrderItemService.selectTOrderItemList(tOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单明细项列表
     */
    //@RequiresPermissions("business:orderitem:export")
    @Log(title = "订单明细项" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TOrderItem tOrderItem) {
        List<TOrderItem> list = tOrderItemService.selectTOrderItemList(tOrderItem);
        ExcelUtil<TOrderItem> util = new ExcelUtil<TOrderItem>(TOrderItem. class);
        util.exportExcel(response, list, "订单明细项数据" );
    }

    /**
     * 获取订单明细项详细信息
     */
    //@RequiresPermissions("business:orderitem:query")
    @GetMapping(value = "/{orderItemId}" )
    public AjaxResult getInfo(@PathVariable("orderItemId" ) String orderItemId) {
        return AjaxResult.success(tOrderItemService.getById(orderItemId));
    }

    /**
     * 新增订单明细项
     */
    //@RequiresPermissions("business:orderitem:add")
    @Log(title = "订单明细项" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrderItem tOrderItem) {
        return toAjax(tOrderItemService.save(tOrderItem));
    }

    /**
     * 修改订单明细项
     */
    //@RequiresPermissions("business:orderitem:edit")
    @Log(title = "订单明细项" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrderItem tOrderItem) {
        return toAjax(tOrderItemService.updateById(tOrderItem));
    }

    /**
     * 删除订单明细项
     */
    //@RequiresPermissions("business:orderitem:remove")
    @Log(title = "订单明细项" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderItemIds}" )
    public AjaxResult remove(@PathVariable String[] orderItemIds) {
        return toAjax(tOrderItemService.removeByIds(Arrays.asList(orderItemIds)));
    }
}
